package org.game.db.bean;

import org.game.db.cache.FormationCache;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.tools.SK_String;
import com.xiaoleilu.hutool.util.StrUtil;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.util.List;
import java.sql.SQLException;
import static org.game.db.StaticResource.FormationResource.*;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import org.game.db.cache.PlayerCache;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.game.db.StaticResource.FormationResource.*;
/**
 * 阵型
 */
public class Formation extends BasePojo<Formation> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[3];
	
	/**
	* id
	*/
	private long id;
	
	/**
	* 玩家ID
	*/
	private int playerId;
	
	/**
	* 状态 0 未启用  1启用
	*/
	private int status;
	
	/**
	* 阵型类型
	*/
	private int type;
	
	/**
	* 阵型位置信息
	*/
	private List stance;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	
	@Deprecated
	public static Formation builder() {
		Formation formation = new Formation();
		return formation;
	}
	
	@Deprecated
	public Formation() {
		super();
	}
	
	public Formation(long id, int playerId, int status, int type, List stance) {
		super();
		this.id = id;
		this.playerId = playerId;
		this.status = status;
		this.type = type;
		this.stance = stance;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
	}
	
	/**
	 * id
	 */
	public long getId() {return id;}
	
	/**
	 * id
	 */
	public Formation setId(long id) {this.id = id;return this;}
	
	/**
	 * 玩家ID
	 */
	public int getPlayerId() {return playerId;}
	
	/**
	 * 玩家ID
	 */
	public Formation setPlayerId(int playerId) {this.playerId = playerId;return this;}
	
	/**
	 * 状态 0 未启用  1启用
	 */
	public int getStatus() {return status;}
	
	/**
	 * 状态 0 未启用  1启用
	 */
	public Formation setStatus(int status) {this.status = status;return this;}
	
	/**
	 * 阵型类型
	 */
	public int getType() {return type;}
	
	/**
	 * 阵型类型
	 */
	public Formation setType(int type) {this.type = type;return this;}
	
	/**
	 * 阵型位置信息
	 */
	public List getStance() {return stance;}
	
	/**
	 * 阵型位置信息
	 */
	public Formation setStance(List stance) {this.stance = stance;return this;}
	
	/**
	 * 阵型位置信息
	 */
	public byte[] getStanceByte() {
		return toBytes(stance);
	}
	
	/**
	 * 阵型位置信息
	 */
	public List initStanceByte(byte[] _byte) {
		return (List)forBytesObject(_byte);
	}	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected Formation setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected Formation setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	
	// 代理
	private org.game.db.proxy.bean.FormationProxy formationProxy = new org.game.db.proxy.bean.FormationProxy().build(this);
	
	public org.game.db.proxy.bean.FormationProxy getFormationProxy(){return formationProxy;}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.playerId;
        values[2] = this.status;
        values[3] = this.type;
        values[4] = this.stance;
        values[5] = this.createDate;
        values[6] = this.modifiedDate;
        return values;
	}
	
	public Formation deepCopy(){
		Formation formation = null;
		try {
			formation = (Formation) super.clone();
		    formation.setStance(ToolCopy.copyObject(this.stance));
		    formation.setCreateDate(ToolCopy.copyObject(this.createDate));
		    formation.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    // 克隆索引
		    formation.indexValues = ArrayUtils.clone(indexValues);
			return formation;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return formation;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.playerId);
        map.put(keys[2], this.status);
        map.put(keys[3], this.type);
        map.put(keys[4], this.stance);
        map.put(keys[5], this.createDate);
        map.put(keys[6], this.modifiedDate);
        return map;
    }
    
    protected Formation createForMap(Object[] keys,Map map){
   		this.id = (long)map.get(keys[0]);
   		this.playerId = (int)map.get(keys[1]);
   		this.status = (int)map.get(keys[2]);
   		this.type = (int)map.get(keys[3]);
   		this.stance = (List)map.get(keys[4]);
   		this.createDate = (java.util.Date)map.get(keys[5]);
   		this.modifiedDate = (java.util.Date)map.get(keys[6]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.playerId);
        obj.put(keys[2], this.status);
        obj.put(keys[3], this.type);
        obj.put(keys[4], toBytes(stance));
        obj.put(keys[5], this.createDate);
        obj.put(keys[6], this.modifiedDate);
        return obj;
    }
    
    protected Formation createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getLongValue(keys[0]);
	    this.playerId = obj.getIntValue(keys[1]);
	    this.status = obj.getIntValue(keys[2]);
	    this.type = obj.getIntValue(keys[3]);
		this.stance = (List)forBytesObject(obj.getBytes(keys[4]));
	    this.createDate = obj.getDate(keys[5]);
	    this.modifiedDate = obj.getDate(keys[6]);
        return this;
    }
    
    
    public Formation createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getLong(SOURCE_COLUMN_NAMES[0]);
	    this.playerId = rs.getInt(SOURCE_COLUMN_NAMES[1]);
	    this.status = rs.getInt(SOURCE_COLUMN_NAMES[2]);
	    this.type = rs.getInt(SOURCE_COLUMN_NAMES[3]);
		this.stance = (List)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[4]));
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[5]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[6]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeLong(this.id);
	    byteBuf.writeInt(this.playerId);
	    byteBuf.writeInt(this.status);
	    byteBuf.writeInt(this.type);
	    byteBuf.writeObject(this.stance);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
    }
	
	protected Formation readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readLong(null);
	    this.playerId = byteBuf.readInt(null);
	    this.status = byteBuf.readInt(null);
	    this.type = byteBuf.readInt(null);
	    this.stance = (List)byteBuf.readObject();
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	/** 取得[player]*/
	public Player getPlayerPkPlayerId(){
		return PlayerCache.me().getById(playerId);
	}
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public Formation insert(){
    	return FormationCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public Formation update(){
    	return FormationCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return FormationCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public Formation insertAndFlush(){
    	return FormationCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Formation updateAndFlush(){
    	return FormationCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return FormationCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public Formation syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getPlayerId(),"_",getType()).e();
		indexValues[2] = SK_Plus.b(getPlayerId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((long)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}